//
//  FSReadViewController.m
//  OASystem
//
//  Created by 刘沿 on 16/5/27.
//  Copyright © 2016年 zpf. All rights reserved.
//

#import "FSReadViewController.h"
#import "OATableViewController.h"
#import "Toast+UIView.h"
#import "HttpTools.h"

@interface FSReadViewController ()<TableViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UITextField *textField;

@end

@implementation FSReadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setLeftItem];

}
//选择发送人
- (IBAction)selectPerson:(id)sender {
    OATableViewController *oat = [[OATableViewController alloc] init];
    
    oat.delegate = self;
    
    [self.navigationController pushViewController:oat animated:YES];
    
}

-(void)TableViewController:(OATableViewController *)viewController array:(NSMutableArray *)array{
    
    NSString *string = [NSString string];

    int index = 0;

    for (NSString *restr in array) {
        if (index == 0) {
              string = [string stringByAppendingString:[NSString stringWithFormat:@"%@",restr]];
        }else {
          string = [string stringByAppendingString:[NSString stringWithFormat:@",%@",restr]];
        
        }
        index ++;
  
    }
    
    self.textField.text = string;

}

//发送
- (IBAction)send:(id)sender {
    
    if (self.textField.text.length == 0) {
     
        [self.view makeToast:@"请选择联系人"];
        
        return;
    }
    
    NSString *userId = [[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
    
    NSArray *array = @[@{@"userId":userId},@{@"unid":self.fileId},@{@"sendto":self.textField.text}];
    
    [HttpTools requestWithURL:KexchRead arrays:array method:KreadFileMethod success:^(id JSON) {
        
        [self.navigationController popToViewController:self.navigationController.viewControllers[2] animated:YES];

        
    } failure:^(NSError *error) {
        
        [self.view makeToast:@"请求错误"];
        
    }];
    
}


- (void)setLeftItem{
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] init];
    
    leftItem.title = @"返回";
    
    self.navigationItem.backBarButtonItem = leftItem;
}

@end
